<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="userInfoId">
        <el-input
          v-model="queryParams.userInfoId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="财富资产年日均" prop="annAssetAver">
        <el-input
          v-model="queryParams.annAssetAver"
          placeholder="请输入财富资产年日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="财富资产月日均" prop="monAssetAver">
        <el-input
          v-model="queryParams.monAssetAver"
          placeholder="请输入财富资产月日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存款年日均" prop="annDepositAver">
        <el-input
          v-model="queryParams.annDepositAver"
          placeholder="请输入存款年日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存款月日均" prop="monDepositAver">
        <el-input
          v-model="queryParams.monDepositAver"
          placeholder="请输入存款月日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信托年日均" prop="annTrustAver">
        <el-input
          v-model="queryParams.annTrustAver"
          placeholder="请输入信托年日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信托月日均" prop="monTrustAver">
        <el-input
          v-model="queryParams.monTrustAver"
          placeholder="请输入信托月日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保险年日均" prop="annInsuranceAver">
        <el-input
          v-model="queryParams.annInsuranceAver"
          placeholder="请输入保险年日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保险月日均" prop="monInsuranceAver">
        <el-input
          v-model="queryParams.monInsuranceAver"
          placeholder="请输入保险月日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基金年日均" prop="annFundAver">
        <el-input
          v-model="queryParams.annFundAver"
          placeholder="请输入基金年日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基金月日均" prop="monFundAver">
        <el-input
          v-model="queryParams.monFundAver"
          placeholder="请输入基金月日均"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="个人贷款余额" prop="loanBalance">
        <el-input
          v-model="queryParams.loanBalance"
          placeholder="请输入个人贷款余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="财富资产余额" prop="assetBalance">
        <el-input
          v-model="queryParams.assetBalance"
          placeholder="请输入财富资产余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存款余额" prop="depositBalance">
        <el-input
          v-model="queryParams.depositBalance"
          placeholder="请输入存款余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信托余额" prop="trustBalance">
        <el-input
          v-model="queryParams.trustBalance"
          placeholder="请输入信托余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基金余额" prop="fundBalance">
        <el-input
          v-model="queryParams.fundBalance"
          placeholder="请输入基金余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有效客户" prop="isValid">
        <el-input
          v-model="queryParams.isValid"
          placeholder="请输入是否有效客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当月中高端评级" prop="currentRate">
        <el-input
          v-model="queryParams.currentRate"
          placeholder="请输入当月中高端评级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信用卡透支余额" prop="overdraftBalance">
        <el-input
          v-model="queryParams.overdraftBalance"
          placeholder="请输入信用卡透支余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="过去12个月客户动账次数" prop="movementsCount">
        <el-input
          v-model="queryParams.movementsCount"
          placeholder="请输入过去12个月客户动账次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kycinfo:finance:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kycinfo:finance:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kycinfo:finance:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kycinfo:finance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="financeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户id" align="center" prop="userInfoId" />
      <el-table-column label="主键id" align="center" prop="financeId" />
      <el-table-column label="财富资产年日均" align="center" prop="annAssetAver" />
      <el-table-column label="财富资产月日均" align="center" prop="monAssetAver" />
      <el-table-column label="存款年日均" align="center" prop="annDepositAver" />
      <el-table-column label="存款月日均" align="center" prop="monDepositAver" />
      <el-table-column label="信托年日均" align="center" prop="annTrustAver" />
      <el-table-column label="信托月日均" align="center" prop="monTrustAver" />
      <el-table-column label="保险年日均" align="center" prop="annInsuranceAver" />
      <el-table-column label="保险月日均" align="center" prop="monInsuranceAver" />
      <el-table-column label="基金年日均" align="center" prop="annFundAver" />
      <el-table-column label="基金月日均" align="center" prop="monFundAver" />
      <el-table-column label="个人贷款余额" align="center" prop="loanBalance" />
      <el-table-column label="财富资产余额" align="center" prop="assetBalance" />
      <el-table-column label="存款余额" align="center" prop="depositBalance" />
      <el-table-column label="信托余额" align="center" prop="trustBalance" />
      <el-table-column label="基金余额" align="center" prop="fundBalance" />
      <el-table-column label="是否有效客户" align="center" prop="isValid" />
      <el-table-column label="当月中高端评级" align="center" prop="currentRate" />
      <el-table-column label="信用卡透支余额" align="center" prop="overdraftBalance" />
      <el-table-column label="过去12个月客户动账次数" align="center" prop="movementsCount" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['kycinfo:finance:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kycinfo:finance:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改kyc金融信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userInfoId">
          <el-input v-model="form.userInfoId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="财富资产年日均" prop="annAssetAver">
          <el-input v-model="form.annAssetAver" placeholder="请输入财富资产年日均" />
        </el-form-item>
        <el-form-item label="财富资产月日均" prop="monAssetAver">
          <el-input v-model="form.monAssetAver" placeholder="请输入财富资产月日均" />
        </el-form-item>
        <el-form-item label="存款年日均" prop="annDepositAver">
          <el-input v-model="form.annDepositAver" placeholder="请输入存款年日均" />
        </el-form-item>
        <el-form-item label="存款月日均" prop="monDepositAver">
          <el-input v-model="form.monDepositAver" placeholder="请输入存款月日均" />
        </el-form-item>
        <el-form-item label="信托年日均" prop="annTrustAver">
          <el-input v-model="form.annTrustAver" placeholder="请输入信托年日均" />
        </el-form-item>
        <el-form-item label="信托月日均" prop="monTrustAver">
          <el-input v-model="form.monTrustAver" placeholder="请输入信托月日均" />
        </el-form-item>
        <el-form-item label="保险年日均" prop="annInsuranceAver">
          <el-input v-model="form.annInsuranceAver" placeholder="请输入保险年日均" />
        </el-form-item>
        <el-form-item label="保险月日均" prop="monInsuranceAver">
          <el-input v-model="form.monInsuranceAver" placeholder="请输入保险月日均" />
        </el-form-item>
        <el-form-item label="基金年日均" prop="annFundAver">
          <el-input v-model="form.annFundAver" placeholder="请输入基金年日均" />
        </el-form-item>
        <el-form-item label="基金月日均" prop="monFundAver">
          <el-input v-model="form.monFundAver" placeholder="请输入基金月日均" />
        </el-form-item>
        <el-form-item label="个人贷款余额" prop="loanBalance">
          <el-input v-model="form.loanBalance" placeholder="请输入个人贷款余额" />
        </el-form-item>
        <el-form-item label="财富资产余额" prop="assetBalance">
          <el-input v-model="form.assetBalance" placeholder="请输入财富资产余额" />
        </el-form-item>
        <el-form-item label="存款余额" prop="depositBalance">
          <el-input v-model="form.depositBalance" placeholder="请输入存款余额" />
        </el-form-item>
        <el-form-item label="信托余额" prop="trustBalance">
          <el-input v-model="form.trustBalance" placeholder="请输入信托余额" />
        </el-form-item>
        <el-form-item label="基金余额" prop="fundBalance">
          <el-input v-model="form.fundBalance" placeholder="请输入基金余额" />
        </el-form-item>
        <el-form-item label="是否有效客户" prop="isValid">
          <el-input v-model="form.isValid" placeholder="请输入是否有效客户" />
        </el-form-item>
        <el-form-item label="当月中高端评级" prop="currentRate">
          <el-input v-model="form.currentRate" placeholder="请输入当月中高端评级" />
        </el-form-item>
        <el-form-item label="信用卡透支余额" prop="overdraftBalance">
          <el-input v-model="form.overdraftBalance" placeholder="请输入信用卡透支余额" />
        </el-form-item>
        <el-form-item label="过去12个月客户动账次数" prop="movementsCount">
          <el-input v-model="form.movementsCount" placeholder="请输入过去12个月客户动账次数" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFinance, getFinance, delFinance, addFinance, updateFinance } from "@/api/kycinfo/finance";

export default {
  name: "Finance",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // kyc金融信息表格数据
      financeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userInfoId: null,
        annAssetAver: null,
        monAssetAver: null,
        annDepositAver: null,
        monDepositAver: null,
        annTrustAver: null,
        monTrustAver: null,
        annInsuranceAver: null,
        monInsuranceAver: null,
        annFundAver: null,
        monFundAver: null,
        loanBalance: null,
        assetBalance: null,
        depositBalance: null,
        trustBalance: null,
        fundBalance: null,
        isValid: null,
        currentRate: null,
        overdraftBalance: null,
        movementsCount: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userInfoId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询kyc金融信息列表 */
    getList() {
      this.loading = true;
      listFinance(this.queryParams).then(response => {
        this.financeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userInfoId: null,
        financeId: null,
        annAssetAver: null,
        monAssetAver: null,
        annDepositAver: null,
        monDepositAver: null,
        annTrustAver: null,
        monTrustAver: null,
        annInsuranceAver: null,
        monInsuranceAver: null,
        annFundAver: null,
        monFundAver: null,
        loanBalance: null,
        assetBalance: null,
        depositBalance: null,
        trustBalance: null,
        fundBalance: null,
        isValid: null,
        currentRate: null,
        overdraftBalance: null,
        movementsCount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.financeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加kyc金融信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const financeId = row.financeId || this.ids
      getFinance(financeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改kyc金融信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.financeId != null) {
            updateFinance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFinance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const financeIds = row.financeId || this.ids;
      this.$modal.confirm('是否确认删除kyc金融信息编号为"' + financeIds + '"的数据项？').then(function() {
        return delFinance(financeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kycinfo/finance/export', {
        ...this.queryParams
      }, `finance_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
